const app = getApp();
const common = require('../../../utils/common.js');
const api = require('../../../config/api.js');

var pageNo = 1;
var hadLastPage = false;
var isLoad = 0;

Page({
	data: {
		imgUrl: app.globalData.imgurl,
		dataList: [],
		showNoData: false,
		showLoding: true,
	},
	onShow: function () {
		this.clearData();
		this.loadList();
	},
	clearData: function () {
		pageNo = 1;
		hadLastPage = false;
		this.setData({
			dataList: []
		});
	},
	loadList: function () {
		isLoad = 1;
		if (hadLastPage) {
			isLoad = 0;
			return;
		}
		var that = this;
		var data = {
			pageNo: pageNo
		}
		this.setData({
			showLoding: true,
			showNoData: false
		});
		setTimeout(function () {
			common.request(api.ProjectCustomerListData, data, 'POST').then(function (data) {
				that.setData({
					showLoding: false
				});
				if (data.type == 'success') {
					var dataList = that.data.dataList;
					for (var i = 0; i < data.data.dataList.length; i++) {
						dataList.push(data.data.dataList[i]);
					}
					if (data.data.pageNo == data.data.totalPages) {
						hadLastPage = true;
					} else {
						pageNo++;
					}
					that.setData({
						dataList: dataList
					});
					isLoad = 0;
					if (data.data.total == 0) {
						that.setData({
							showNoData: true
						});
					}
				} else {
					console.log(data.content);
					isLoad = 0;
				}
			});
		}, app.globalData.showLodingTime);
	},
	onReachBottom: function () {
		this.loadList();
	}
})